import Taro from '@tarojs/taro';
import {paymentApiRequest} from '../utils/aepApiRequest';

export async function getRechargePackageList({type = '1'}: {type: string}) {
  const user_id = Taro.getStorageSync('uid');
  const path = `v3/users/${user_id}/goods?type=${type}`;
  return paymentApiRequest(path, {
    method: 'GET',
  });
}

export async function payRechargePackage({id, openid, deviceId}: {id: string, openid: string, deviceId: string}) {
  const user_id = Taro.getStorageSync('uid');
  const path = `v3/users/${user_id}/orders`;
  return paymentApiRequest(path, {
    method: 'POST',
    body: {
      channel: 1,
      good_id: id,
      openid: openid,
      device_id: deviceId,
    },
  });
}

export async function getRechargeRecordList() {
  const user_id = Taro.getStorageSync('uid');
  const path = `v3/users/${user_id}/orders`;
  return paymentApiRequest(path, {
    method: 'GET',
  });
}

export async function getRecorderDetail({id}: {id: string}) {
  const user_id = Taro.getStorageSync('uid');
  const path = `v3/users/${user_id}/orders/${id}`;
  return paymentApiRequest(path, {
    method: 'GET',
  });
}

